#include<iostream>
#include<vector>
#include<set>
#define pb push_back
using namespace std;
const int N=1e5+5,INF=0x3f3f3f3f;
int n,id[N];
vector<int>G[N];
#define PII pair<int,int>
#define fi first
#define se second
multiset<PII>S[N];
inline void dfs(int x,int fa){
	if(fa&&G[x].size()==1)
		return S[x].insert({1,0}),void();
	for(auto v:G[x])
		if(v!=fa){
		dfs(v,x);
		if(S[v].size()>S[x].size()) swap(S[x],S[v]);
		for(auto val:S[v]) S[x].insert(val);
		S[v].clear();
	}
	if(S[x].size()>1){
		auto it=S[x].end();
		PII v1=*(--it),v2=*(--it);
		S[x].erase(S[x].find(v1)),S[x].erase(S[x].find(v2));
		S[x].insert({v1.fi+v2.fi+1,v1.se+v2.se});
	}
	else{
		PII v=*S[x].begin();
		S[x].clear(),S[x].insert({v.fi,v.se+1});
		S[x].insert({1,-1});
	}
}
signed main(){
	freopen("bird.in","r",stdin);
	freopen("bird.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=1,u,v;i<n;++i)
		cin>>u>>v,G[u].pb(v),G[v].pb(u);
	dfs(1,0);
	PII ans=*S[1].rbegin();
	cout<<(ans.fi+(ans.se>0))<<"\n";
}